package com.gqz.equip.app.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.gqz.common.core.domain.RequestForm;
import com.gqz.common.core.utils.poi.ExcelUtil;
import com.gqz.common.core.utils.query.QueryMapperUtil;
import com.gqz.equip.app.entity.EnWzEquipBqEntity;
import com.gqz.equip.app.entity.TEnWzEquipEntity;
import com.gqz.equip.app.entity.TEquipByTypeEntity;
import com.gqz.equip.app.mapper.TEnWzEquipMapper;
import com.gqz.equip.app.mapper.TEquipByTypeMapper;
import com.gqz.equip.app.mapstruct.TEnWzEquipMapstruct;
import com.gqz.equip.app.mapstruct.TEquipByTypeMapstruct;
import com.gqz.equip.app.service.MqTEnWzEquipService;
import com.gqz.equip.vo.*;
import jakarta.annotation.Resource;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 新能源设备信息 业务逻辑实现层ServiceImpl
 *
 * @Version 1.0
 * @Author input you name
 */
@Service
@Slf4j
public class MqEnWzEquipServiceImpl extends ServiceImpl<TEnWzEquipMapper, TEnWzEquipEntity> implements MqTEnWzEquipService {

    @Autowired
    private TEnWzEquipMapstruct mapstruct;

    @Resource
    private TEquipByTypeMapper tEquipByTypeMapper;

    @Resource
    private TEquipByTypeMapstruct tEquipByTypeMapstruct;

    @Value("${load-image}")
    private String loadImage;


    @Override
    public List<TEnWzEquipVo> getById(String id) {
        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(TEnWzEquipEntity::getSbbm, id);
        queryWrapper.selectAll(TEnWzEquipEntity.class);
        List<TEnWzEquipEntity> entities = baseMapper.selectList(queryWrapper);
        if (CollectionUtils.isNotEmpty(entities)) {
            return mapstruct.toVos(entities);
        }
        return new ArrayList<>();
    }

    @Override
    public Page<TEnWzEquipVo> page(RequestForm<TEnWzEquipVo> requestForm) {
        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(TEnWzEquipEntity.class);
        queryWrapper.selectAs(EnWzEquipBqEntity::getIsTq, "sftq");
        queryWrapper.select(EnWzEquipBqEntity::getDlwz);
        queryWrapper.select(EnWzEquipBqEntity::getZb);
        queryWrapper.select(EnWzEquipBqEntity::getEwmzp);
        queryWrapper.leftJoin(EnWzEquipBqEntity.class, on -> {
            on.eq(EnWzEquipBqEntity::getSbbm, TEnWzEquipEntity::getSbbm);
            on.eq(EnWzEquipBqEntity::getIsDel, 0);
            return on;
        });
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, 0);
        if (requestForm.getEntity().getSfjc() != null && !"".equals(requestForm.getEntity().getSfjc())) {
            queryWrapper.eq(TEnWzEquipEntity::getSfjc, requestForm.getEntity().getSfjc());
        }
        if (requestForm.getEntity().getSbmc() != null && !"".equals(requestForm.getEntity().getSbmc())) {
            queryWrapper.like(TEnWzEquipEntity::getSbmc, requestForm.getEntity().getSbmc());
        }
        if (requestForm.getEntity().getCcbm() != null && !"".equals(requestForm.getEntity().getCcbm())) {
            queryWrapper.like(TEnWzEquipEntity::getCcbm, requestForm.getEntity().getCcbm());
        }
        if (requestForm.getEntity().getWzlbbm() != null && !"".equals(requestForm.getEntity().getWzlbbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getWzlbbm, requestForm.getEntity().getWzlbbm());
        }
        if (requestForm.getEntity().getSbgg() != null && !"".equals(requestForm.getEntity().getSbgg())) {
            queryWrapper.like(TEnWzEquipEntity::getSbgg, requestForm.getEntity().getSbgg());
        }
        if (requestForm.getEntity().getXh() != null && !"".equals(requestForm.getEntity().getXh())) {
            queryWrapper.like(TEnWzEquipEntity::getXh, requestForm.getEntity().getXh());
        }
        if (requestForm.getEntity().getGldwbm() != null && !"".equals(requestForm.getEntity().getGldwbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getGldwbm, requestForm.getEntity().getGldwbm());
        }
        if (requestForm.getEntity().getSblxbm() != null && !"".equals(requestForm.getEntity().getSblxbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getSblxbm, requestForm.getEntity().getSblxbm());
        }
        if (requestForm.getEntity().getYxzt() != null && !"".equals(requestForm.getEntity().getYxzt())) {
            queryWrapper.eq(TEnWzEquipEntity::getYxzt, requestForm.getEntity().getYxzt());
        }
        if (requestForm.getEntity().getSskfbm() != null && !"".equals(requestForm.getEntity().getSskfbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getSskfbm, requestForm.getEntity().getSskfbm());
        }
        if (requestForm.getEntity().getSskfmc() != null && !"".equals(requestForm.getEntity().getSskfmc())) {
            queryWrapper.like(TEnWzEquipEntity::getSskfmc, requestForm.getEntity().getSskfmc());
        }
        if (requestForm.getEntity().getSftq() != null && "1".equals(requestForm.getEntity().getSftq())) {
            queryWrapper.eq(EnWzEquipBqEntity::getIsTq, requestForm.getEntity().getSftq());
        } else if ("0".equals(requestForm.getEntity().getSftq())) {
            queryWrapper.isNull(EnWzEquipBqEntity::getIsTq);
        }
        if (requestForm.getEntity().getSbztbm() != null && !"".equals(requestForm.getEntity().getSbztbm())) {
            String sbztbms = requestForm.getEntity().getSbztbm();
            String[] sbztbm = sbztbms.split(",");
            queryWrapper.in(TEnWzEquipEntity::getSbztbm, Arrays.asList(sbztbm));
        }
        Page<TEnWzEquipVo> page = Page.of(requestForm.getPageNo(), requestForm.getPageSize());
        IPage<TEnWzEquipVo> iPage = baseMapper.selectJoinPage(page, TEnWzEquipVo.class, queryWrapper);
        List<TEnWzEquipVo> records = iPage.getRecords().stream().map(item -> {
            if (item != null) {
                if ("0".equals(item.getSftq()) || "".equals(item.getSftq()) || null == item.getSftq()) {
                    item.setSftq("否");
                } else {
                    item.setSftq("是");
                }
            }
            return item;
        }).collect(Collectors.toList());
        iPage.setRecords(records);
        page.setTotal(iPage.getTotal());
        return page;
    }

    @Override
    public Long count(RequestForm<TEnWzEquipVo> requestForm) {
        TEnWzEquipEntity entity = mapstruct.toEntity(requestForm.getEntity());
        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = QueryMapperUtil.initQueryWrapper(entity, requestForm);
        queryWrapper.select(TEnWzEquipEntity::getSbbm);
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, 0);
        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public int insert(List<TEnWzEquipVo> vos) {
        List<TEnWzEquipEntity> entitys = mapstruct.toEntitys(vos);
        int result = 0;
        for (int i = 0, size = entitys.size(); i < size; i++) {
            TEnWzEquipEntity entity = entitys.get(i);
            entity.setSbztbm("0");
            entity.setSbztmc("初始设备");
            entity.setSbztOld("0");
            entity.setSbztOldmc("初始设备");

            result += baseMapper.insert(entity);
        }
        return result;
    }

    @Override
    public int update(List<TEnWzEquipVo> vos) {
        List<TEnWzEquipEntity> entitys = mapstruct.toEntitys(vos);
        int result = 0;
        for (int i = 0, size = entitys.size(); i < size; i++) {
            TEnWzEquipEntity entity = entitys.get(i);
            result += baseMapper.updateById(entity);
        }
        return result;
    }


    @Override
    public Page<TEnWzEquipBqVo> pageBqList(RequestForm<TEnWzEquipBqVo> requestForm) {

        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = new MPJLambdaWrapper<>();

        queryWrapper.selectAll(TEnWzEquipEntity.class);
//        queryWrapper.selectIgnore(TEnWzEquipEntity::getSftq);
        queryWrapper.select(EnWzEquipBqEntity::getId);
        queryWrapper.select(EnWzEquipBqEntity::getTqrName);
        queryWrapper.select(EnWzEquipBqEntity::getTqrId);
        queryWrapper.select(EnWzEquipBqEntity::getTqTime);
        queryWrapper.select(EnWzEquipBqEntity::getQjzp);
        queryWrapper.select(EnWzEquipBqEntity::getEwmzp);
        queryWrapper.select(EnWzEquipBqEntity::getShztmc);
        queryWrapper.select(EnWzEquipBqEntity::getShztbm);
        queryWrapper.select(EnWzEquipBqEntity::getShyj);
        queryWrapper.select(EnWzEquipBqEntity::getShPerson);
        queryWrapper.select(EnWzEquipBqEntity::getShTime);
        queryWrapper.select(EnWzEquipBqEntity::getZb);
        queryWrapper.select(EnWzEquipBqEntity::getDlwz);
        queryWrapper.selectAs(EnWzEquipBqEntity::getIsTq, "sftq");
        queryWrapper.leftJoin(EnWzEquipBqEntity.class, EnWzEquipBqEntity::getSbbm, TEnWzEquipEntity::getSbbm);
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, 0);
        if (requestForm.getEntity().getSbbm() != null && !"".equals(requestForm.getEntity().getSbbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getSbbm, requestForm.getEntity().getSbbm());
        }
        if (requestForm.getEntity().getCcbm() != null && !"".equals(requestForm.getEntity().getCcbm())) {
            queryWrapper.like(TEnWzEquipEntity::getCcbm, requestForm.getEntity().getCcbm());
        }
        if (requestForm.getEntity().getSbgg() != null && !"".equals(requestForm.getEntity().getSbgg())) {
            queryWrapper.like(TEnWzEquipEntity::getSbgg, requestForm.getEntity().getSbgg());
        }
        if (requestForm.getEntity().getSblxbm() != null && !"".equals(requestForm.getEntity().getSblxbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getSblxbm, requestForm.getEntity().getSblxbm());
        }
        if (requestForm.getEntity().getSbmc() != null && !"".equals(requestForm.getEntity().getSbmc())) {
            queryWrapper.like(TEnWzEquipEntity::getSbmc, requestForm.getEntity().getSbmc());
        }
        //&& !"BJ-EN-001".equals(requestForm.getEntity().getGldwbm())
        if (requestForm.getEntity().getGldwbm() != null && !"".equals(requestForm.getEntity().getGldwbm())) {
            queryWrapper.like(TEnWzEquipEntity::getGldwbm, requestForm.getEntity().getGldwbm());
        }
        if (requestForm.getEntity().getYxzt() != null && !"".equals(requestForm.getEntity().getYxzt())) {
            queryWrapper.like(TEnWzEquipEntity::getYxzt, requestForm.getEntity().getYxzt());
        }
        if (requestForm.getEntity().getSftq() != null && "1".equals(requestForm.getEntity().getSftq())) {
            queryWrapper.eq(EnWzEquipBqEntity::getIsTq, requestForm.getEntity().getSftq());
        } else if ("0".equals(requestForm.getEntity().getSftq())) {
            queryWrapper.isNull(EnWzEquipBqEntity::getIsTq);
        }
        if (requestForm.getEntity().getShztbm() != null && !"".equals(requestForm.getEntity().getShztbm())) {
            queryWrapper.eq(EnWzEquipBqEntity::getShztbm, requestForm.getEntity().getShztbm());
        }

        if (requestForm.getEntity().getTqTime() != null) {
            //queryWrapper.ge(  :: getTestTime, Timestamp.valueOf(requestForm.getEntity().getTqTime()));
            queryWrapper.ge(EnWzEquipBqEntity::getTqTime, requestForm.getEntity().getTqTime());
        }
        if (requestForm.getEntity().getTqTime_to() != null) {
            //queryWrapper.ge(  :: getTestTime, Timestamp.valueOf(requestForm.getEntity().getTqTime()));
            queryWrapper.le(EnWzEquipBqEntity::getTqTime, requestForm.getEntity().getTqTime_to());
        }
        queryWrapper.orderByDesc(EnWzEquipBqEntity::getIsTq);
        queryWrapper.orderByDesc(EnWzEquipBqEntity::getTqTime);
        Page<TEnWzEquipBqVo> page = Page.of(requestForm.getPageNo(), requestForm.getPageSize());
        //page = baseMapper.selectPage(page, queryWrapper);
        IPage<TEnWzEquipBqVo> iPage = baseMapper.selectJoinPage(page, TEnWzEquipBqVo.class, queryWrapper);

        List<TEnWzEquipBqVo> records = iPage.getRecords().stream().map(item -> {
            if (item != null) {
                if ("0".equals(item.getSftq()) || "".equals(item.getSftq()) || null == item.getSftq()) {
                    item.setSftq("否");
                } else {
                    item.setSftq("是");
                }

            }
            return item;
        }).collect(Collectors.toList());
        iPage.setRecords(records);
        page.setTotal(iPage.getTotal());
        return page;
    }

    @Override
    public List<TEnWzEquipBqVo> getBqxxById(String id) {
        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(TEnWzEquipEntity.class);
        queryWrapper.select(EnWzEquipBqEntity::getId);
//        queryWrapper.selectAs(EnWzEquipBqEntity::getTqrName, "tqr");
        queryWrapper.select(EnWzEquipBqEntity::getTqrName);
        queryWrapper.select(EnWzEquipBqEntity::getTqrId);
        queryWrapper.select(EnWzEquipBqEntity::getTqTime);
        queryWrapper.select(EnWzEquipBqEntity::getQjzp);
        queryWrapper.select(EnWzEquipBqEntity::getEwmzp);
        queryWrapper.select(EnWzEquipBqEntity::getShztmc);
        queryWrapper.select(EnWzEquipBqEntity::getShztbm);
        queryWrapper.select(EnWzEquipBqEntity::getShyj);
        queryWrapper.select(EnWzEquipBqEntity::getShPerson);
        queryWrapper.select(EnWzEquipBqEntity::getShTime);
        queryWrapper.leftJoin(EnWzEquipBqEntity.class, EnWzEquipBqEntity::getSbbm, TEnWzEquipEntity::getSbbm);
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, 0);
        queryWrapper.eq(EnWzEquipBqEntity::getId, id);
        // List<TEnWzEquipBqVo> entities = baseMapper.selectList(queryWrapper);
        List<TEnWzEquipBqVo> entities = baseMapper.selectJoinList(TEnWzEquipBqVo.class, queryWrapper);
        // TEnWzEquipBqVo  entities1 = baseMapper.selectJoinOne(TEnWzEquipBqVo.class,queryWrapper);
        if (CollectionUtils.isNotEmpty(entities)) {
            return entities;
        }
        return new ArrayList<>();
    }

    @Override
    public List<TEnWzEquipBqVo> getList(TEnWzEquipBqVo requestForm) {
        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(TEnWzEquipEntity.class);
        queryWrapper.select(EnWzEquipBqEntity::getId);
        queryWrapper.select(EnWzEquipBqEntity::getTqrName);
        queryWrapper.select(EnWzEquipBqEntity::getTqrId);
        queryWrapper.select(EnWzEquipBqEntity::getTqTime);
        queryWrapper.select(EnWzEquipBqEntity::getQjzp);
        queryWrapper.select(EnWzEquipBqEntity::getEwmzp);
        queryWrapper.select(EnWzEquipBqEntity::getShztmc);
        queryWrapper.select(EnWzEquipBqEntity::getShztbm);
        queryWrapper.select(EnWzEquipBqEntity::getShyj);
        queryWrapper.select(EnWzEquipBqEntity::getShPerson);
        queryWrapper.select(EnWzEquipBqEntity::getShTime);
        queryWrapper.selectAs(EnWzEquipBqEntity::getIsTq, "sftq");
        queryWrapper.leftJoin(EnWzEquipBqEntity.class, EnWzEquipBqEntity::getSbbm, TEnWzEquipEntity::getSbbm);
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, 0);
        queryWrapper.orderByDesc(EnWzEquipBqEntity::getIsTq);
        queryWrapper.orderByDesc(EnWzEquipBqEntity::getTqTime);
        if (requestForm.getSbbm() != null && !"".equals(requestForm.getSbbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getSbbm, requestForm.getSbbm());
        }
        if (requestForm.getCcbm() != null && !"".equals(requestForm.getCcbm())) {
            queryWrapper.like(TEnWzEquipEntity::getCcbm, requestForm.getCcbm());
        }
        if (requestForm.getSbgg() != null && !"".equals(requestForm.getSbgg())) {
            queryWrapper.like(TEnWzEquipEntity::getSbgg, requestForm.getSbgg());
        }
        if (requestForm.getSblxbm() != null && !"".equals(requestForm.getSblxbm())) {
            queryWrapper.eq(TEnWzEquipEntity::getSblxbm, requestForm.getSblxbm());
        }
        if (requestForm.getSbmc() != null && !"".equals(requestForm.getSbmc())) {
            queryWrapper.like(TEnWzEquipEntity::getSbmc, requestForm.getSbmc());
        }
        if (requestForm.getSftq() != null && "1".equals(requestForm.getSftq())) {
            queryWrapper.eq(EnWzEquipBqEntity::getIsTq, requestForm.getSftq());
        } else if ("0".equals(requestForm.getSftq())) {
            queryWrapper.isNull(EnWzEquipBqEntity::getIsTq);
        }
        if (requestForm.getShztbm() != null && !"".equals(requestForm.getShztbm())) {
            queryWrapper.eq(EnWzEquipBqEntity::getShztbm, requestForm.getShztbm());
        }

        if (requestForm.getTqTime() != null) {
            queryWrapper.ge(EnWzEquipBqEntity::getTqTime, requestForm.getTqTime());
        }
        if (requestForm.getTqTime_to() != null) {
            queryWrapper.le(EnWzEquipBqEntity::getTqTime, requestForm.getTqTime_to());
        }
        List<TEnWzEquipBqVo> entities = baseMapper.selectJoinList(TEnWzEquipBqVo.class, queryWrapper);
        for (int i = 0; i < entities.size(); i++) {
            String sftq = entities.get(i).getSftq();
            String qjzp = entities.get(i).getQjzp();
            String ewmzp = entities.get(i).getEwmzp();
            if ("0".equals(sftq) || "".equals(sftq) || null == sftq) {
                entities.get(i).setSftq("否");
            } else {
                entities.get(i).setSftq("是");
            }
            if (!"".equals(qjzp) && null != qjzp) {
                String url = loadImage + qjzp.split(",")[0] + "/qjzp.png";
                entities.get(i).setQjzp(url);
            }
            if (!"".equals(ewmzp) && null != ewmzp) {
                String url = loadImage + ewmzp.split(",")[0] + "/ewmzp.png";
                entities.get(i).setEwmzp(url);
            }
        }
        if (CollectionUtils.isNotEmpty(entities)) {
            return entities;
        }
        return new ArrayList<>();
    }


    /**
     * 根据设备类型分组查询设备数量
     */
    @Override
    public List<TEquipByTypeVo> queryByEquipType() {
        MPJLambdaWrapper<TEquipByTypeEntity> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAs(TEnWzEquipEntity::getSblxbm, "serverType");
        queryWrapper.selectCount(TEnWzEquipEntity::getSbbm, "countAll");
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, "0");
        queryWrapper.eq(TEnWzEquipEntity::getYxzt, "20");
        //目前这些类型
        queryWrapper.in(TEnWzEquipEntity::getSblxbm, "100001", "100002", "100003", "100004");
        queryWrapper.groupBy(TEnWzEquipEntity::getSblxbm);
        List<TEquipByTypeEntity> equipTypeList = tEquipByTypeMapper.selectList(queryWrapper);
        return tEquipByTypeMapstruct.toVos(equipTypeList);
    }

    // 防止使用'IN'出现数据参数集合为空导致程序无法正常进行情况
    private static final List<String> DEFAULT_IN_LIST = new ArrayList<>(1);

    static {
        DEFAULT_IN_LIST.add("-1");
    }

    // 常量生声明处
    public static final String NOT_DEL = "0";

    /**
     * @author: huangLb
     * @description: 根据设备编号s查询对应设备信息集合-要求拆分完的size不得大于1000,否则无法获取正常数据
     */
    @Override
    public List<TEnWzEquipVo> queryEquipByEquipNos(String equipNos) {
        if (StrUtil.isBlank(equipNos)) {
            // 无实际参数则直接返回空集合
            return Collections.emptyList();
        }

        // 转为List集合--- size > 1
        List<String> equipNoList = Arrays.stream(
                StrUtil.splitToArray(equipNos, StrUtil.COMMA)).collect(Collectors.toList());
        if (equipNoList.size() > 1000) {
            // IN限制
            return Collections.emptyList();
        }

        // 查询结果并转化VO返回
        List<TEnWzEquipEntity> equipInfoList =
                this.lambdaQuery()
                        .select(TEnWzEquipEntity::getSbbm, TEnWzEquipEntity::getSbmc, TEnWzEquipEntity::getCcbm,
                                TEnWzEquipEntity::getSblxbm, TEnWzEquipEntity::getSblxmc,
                                TEnWzEquipEntity::getJlfsbm, TEnWzEquipEntity::getJlfsmc,
                                TEnWzEquipEntity::getSbgg, TEnWzEquipEntity::getXh,
                                TEnWzEquipEntity::getPt, TEnWzEquipEntity::getCt,
                                TEnWzEquipEntity::getSfjc, TEnWzEquipEntity::getCjmc,
                                TEnWzEquipEntity::getYxzt, TEnWzEquipEntity::getYxztmc)
                        .eq(TEnWzEquipEntity::getSfsc, NOT_DEL)
                        .in(TEnWzEquipEntity::getSbbm, equipNoList).list();
        return this.mapstruct.toVos(equipInfoList);
    }

    @Override
    public Integer creatEwmByList(List<TEnWzEquipVo> vos) {
        List<TEnWzEquipEntity> entitys = mapstruct.toEntitys(vos);
        int result = 0;
        for (int i = 0, size = entitys.size(); i < size; i++) {
            //设备类型、设备名称、设备编码、出厂编码都不为空时可生成二维码照片
            if (entitys.get(i).getSbbm() != null && entitys.get(i).getSbmc() != null && entitys.get(i).getSblxbm() != null && entitys.get(i).getCcbm() != null) {
                TEnWzEquipEntity entity = entitys.get(i);
                entity.setEwm("1");
                result += baseMapper.updateById(entity);
            }
        }
        return result;
    }


    @SneakyThrows
    @Override
    public void exportExcel(HttpServletResponse response, RequestForm<TEnWzEquipBqVo> requestForm) {
        //设置信息头，告诉浏览器内容为excel类型
        response.setHeader("content-Type", "application/vnd.ms-excel");
        //文件名称
        String fileName = "设备标签信息.xls";
        //sheet名称
        String sheetName = "设备标签信息";
        //设置下载名称
        response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
        //字节流输�?
        ServletOutputStream out = response.getOutputStream();
        //设置excel参数
        //获取到业务数�?
        List<TEnWzEquipBqVo> page = this.getList(requestForm.getEntity());

        ExcelUtil<TEnWzEquipBqVo> util = new ExcelUtil<>(TEnWzEquipBqVo.class);
        util.exportExcel(response, page, sheetName);
    }

    @Override
    public WzEquipTjVo wzEquipTj(TEnWzEquipVo vos) {
        //各类型数量
        MPJLambdaWrapper<TEnWzEquipEntity> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.eq(TEnWzEquipEntity::getSfsc, "0");
        queryWrapper.select(TEnWzEquipEntity::getSblxmc);
        queryWrapper.select(TEnWzEquipEntity::getSblxbm);
        queryWrapper.selectCount(TEnWzEquipEntity::getSblxbm, "equipNum");
        queryWrapper.groupBy(TEnWzEquipEntity::getSblxbm);
        queryWrapper.groupBy(TEnWzEquipEntity::getSblxmc);
        if (vos.getGldwbm() != null && !"BJ-EN-001".equals(vos.getGldwbm()) && !"".equals(vos.getGldwbm())) {
            queryWrapper.like(TEnWzEquipEntity::getGldwbm, vos.getGldwbm());
        }
//        List<TEnWzEquipEntity> entities = baseMapper.selectList(queryWrapper);
        List<WzEquipBylxVo> resultList = baseMapper.selectJoinList(WzEquipBylxVo.class, queryWrapper);
        WzEquipTjVo wzEquipTjVo = new WzEquipTjVo();
        wzEquipTjVo.setWzEquipList(resultList);
        //总数
        int equipsum = 0;
        for (int i = 0; i < resultList.size(); i++) {
            equipsum += resultList.get(i).getEquipNum();
        }
        wzEquipTjVo.setAllNum(equipsum);
        return wzEquipTjVo;
    }

}
